package com.yanqu.road.server.cmd.activity.shuihuyezicard;

import com.yanqu.road.entity.activity.shuihuyezipai.ShuiHuYeZiCardUserCard;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.activity.ShuiHuYeZiCardProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.activity.shuihuyezipai.ShuiHuYeZiCardActivityBattleMgr;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description
 * @Author cwq
 * @Data 2021/12/7 18:05
 */
@Cmd(code = CrossProtocol.C_CROSS_SHUIHUYEZICARD_START_GAME, desc = "水浒叶子牌 开始匹配")
public class CrossShuiHuYeZiCardStartGameCmd extends CrossCommand {

    long userId;
    int activityId;
    int rankScore;
    int roomType;
    Map<Integer, ShuiHuYeZiCardUserCard> cardMap = new HashMap<>();

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        ShuiHuYeZiCardProto.ShuiHuYeZiGetCardStartGameToCrossMsg reqMsg = ShuiHuYeZiCardProto.ShuiHuYeZiGetCardStartGameToCrossMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        rankScore = reqMsg.getRankScore();
        roomType = reqMsg.getRoomType();
        userId = packet.getPlayerId();
        CrossUserMgr.updateUserBaseInfo(userId,PlayerBasePb.parseToUserBaseInfo(reqMsg.getPlayerInfo()));
        for (ShuiHuYeZiCardProto.ShuiHuYeZiCardUserCardEntity item : reqMsg.getCardListList()){
            ShuiHuYeZiCardUserCard card = new ShuiHuYeZiCardUserCard();
            card.setId(item.getId());
            card.setLevel(item.getLevel());
            card.setQuality(item.getQuality());
            cardMap.put(item.getId(),card);
        }
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        ShuiHuYeZiCardActivityBattleMgr.startMatch(activityId,serverId,userId,rankScore,roomType,cardMap);
    }

    @Override
    public void sendData() {

    }
}
